# Determine the XInput API include and library paths. 
# Once done, the following is defined
#  XINPUT_FOUND 
#  XInput_INCLUDE_DIR 
#  XInput_LIBRARY 
IF( CMAKE_SYSTEM_NAME MATCHES Windows )

	# The main/root path where XInput should be found (this can be the DirectX SDK install path or the Platform SDK)
	SET( XInput_SDK_ROOT_PATH "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)" CACHE STRING "The root path of the SDK providing XInput (for example: DirectX or Platform SDK)" )
	
	# Determine the header path
	FIND_PATH( XInput_INCLUDE_DIR NAMES XInput.h PATHS "${XInput_SDK_ROOT_PATH}/Include" NO_DEFAULT_PATH  )
		
	# Determine the library path depending on the architecture (x86 or x64)
	# The structure of Microsoft SDKs (DirectX and Platform) are not the same regarding libs
	# In the DirectX SDK (at least the June 2010 one), libs are stored in two folders: x86 and x64
	# In the Platform SDK, the x86 libs are at the root and x64 in a folder.
	IF ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
		FIND_LIBRARY( XInput_LIBRARY NAMES XInput PATHS "${XInput_SDK_ROOT_PATH}/Lib/x64" NO_DEFAULT_PATH )
	ELSE()
		FIND_LIBRARY( XInput_LIBRARY NAMES XInput PATHS "${XInput_SDK_ROOT_PATH}/Lib/x86" "${XInput_SDK_ROOT_PATH}/Lib" NO_DEFAULT_PATH )
	ENDIF()
		
	INCLUDE( FindPackageHandleStandardArgs )
	FIND_PACKAGE_HANDLE_STANDARD_ARGS( XInput DEFAULT_MSG XInput_LIBRARY XInput_INCLUDE_DIR )
		
ENDIF()